'''
Author: LHY 2601958675@qq.com
Date: 2023-12-09 11:35:08
LastEditors: LHY
LastEditTime: 2023-12-13 11:20:58
Description: 
'''
# https://www.pinterest.com/applecheung99/%E4%B8%80%E4%BA%8C%E5%B8%83%E5%B8%83/
# https://getstickerpack.com/stickers/xiong-mao-yi-erdi-ba-dan-bu-bu-1
# # https://www.qiubiaoqing.com/search/user_album_imgs/%E4%B8%80%E4%BA%8C%E5%B8%83%E5%B8%83%E8%A1%A8%E6%83%85%E5%8C%85.html
# https://51cg1.com/archives/72487/
# https://v.douyin.com/i86bGxpx/
import requests
from lxml import etree
import os



session  = requests.session()

def getpage(page,search):
    # /images/search/美女/
    session.get("https://pixabay.com/zh")
    header = {"Accept-Language":"zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7","Referer":"https://pixabay.com/zh/","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}
    url =  f"https://www.qiubiaoqing.com/api/search/page_data?search_type=user_album_imgs&search_key={search}&page={page}" 
    res = session.get(url,headers=header)
    res.encoding = 'utf-8'
    # print("asa",res.json()["data"])
    list = res.json()["data"]["list"]
    for item in list:
        img_url = item["img_url"]
        imageName = img_url.rsplit("/",1)[1].replace(".git","")
        image_respon = requests.get(img_url)
        print(img_url)
        print(imageName)
        print('/n\n')
        filepath = f"{search}/{page}/{imageName}"
        folderpath = os.path.dirname(filepath)
        print("filepath=",filepath)
        print("folderpath=",folderpath)  
        # 如果文件夹不存在，创建文件夹
        if not os.path.exists(folderpath):
            os.makedirs(folderpath)

        # print(folderpath)    
        with open(filepath, 'wb') as f:#f'/Users/apple/gitee/think-for-yourself/Scrapy学习/tutorial/images/{imageName}'
            f.write(image_respon.content)
    # htmlObj = etree.HTML(res.text)
    # lis = htmlObj.xpath('//body/script[1]/text()')[0]
    # # print(lis)
    # obj = re.compile(r"window.__BOOTSTRAP_URL__ = '(?P<name>.*?)';",re.S)#re.S可以让.匹配换行
    # reszj = obj.finditer(lis)
    # returnUrl = ""
    # for item in reszj:
    #     name = item.group("name").strip()
    #     returnUrl = name
    #     break
    # return returnUrl
pass  




# getpage(1,"一二布布") 

def getpage2():
    res = requests.get("https://getstickerpack.com/stickers/xiong-mao-yi-erdi-ba-dan-bu-bu-1")
    res.encoding = 'utf-8'
    # print(res.text)
    et = etree.HTML(res.text)
    findList = et.xpath('//div[@class="col-xl-3 col-lg-3 col-md-3 col-sm-4 col-4 sticker-pack-cols"]')
    print(findList)
    # title = et.xpath('//h1[@id="myheader"]/text()')[0]
    for item in findList:
        img_url = item.xpath(".//img/@src")[0].rsplit('?',1)[0]
        print(img_url)
        image_respon = requests.get(img_url)
        filepath = f"一二布布/xpath/{img_url}"
        folderpath = os.path.dirname(filepath)
         # 如果文件夹不存在，创建文件夹
        if not os.path.exists(folderpath):
            os.makedirs(folderpath)

        # print(folderpath)    
        with open(filepath, 'wb') as f:#f'/Users/apple/gitee/think-for-yourself/Scrapy学习/tutorial/images/{imageName}'
            f.write(image_respon.content)
    pass

# getpage2()

def douyin():
    session.get("https://v.douyin.com/i86bGxpx/")
    
#     header = {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
# "Accept-Encoding": "gzip, deflate, br",
# "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
# "Cache-Control":"max-age=0",
# "Connection": "keep-alive",
# "Cookie": "ttwid=1%7CbopXZucLd0bVc9JGao7U1gAuFK0qJ-mEwdRhLO1Ckas%7C1670663338%7C8205e2f2d51779f9768e9bd158a8563df0d38f37990de22513875ec0f64a0f30; n_mh=InES1BRVmb6X4Dotgvt2eX6_2xGe60HhkoNxrl0aqB0; LOGIN_STATUS=1; store-region=cn-bj; store-region-src=uid; my_rd=1; passport_csrf_token=1b4500e4563f57661e7e7761214a2bd0; passport_csrf_token_default=1b4500e4563f57661e7e7761214a2bd0; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.6%7D; SEARCH_RESULT_LIST_TYPE=%22single%22; IsDouyinActive=true; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A2880%2C%5C%22screen_height%5C%22%3A1620%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A4%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A250%7D%22; home_can_add_dy_2_desktop=%221%22; strategyABtestKey=%221702434974.731%22; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCSHBqWnRPdk5nS0phWmhIeEgzTUdJandSNmJkbVlheHkrMVAwczdBVG1jYVZCcC90Vnl4QWw2ZmFDc0pEWmhaYXhVZ0EwVlBjZnpFUWw4SW5EcGRYU2s9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; bd_ticket_guard_client_web_domain=2; pwa2=%220%7C0%7C1%7C0%22; s_v_web_id=verify_lq35voy0_77FJbCKc_ZVkb_4qae_AotC_znF0zK21CDdd; msToken=NMgqZtWW3cGLBeABUWmh9W6K3Wj7XFkx72VK0-J6PD91xIj-mn4sWWiyKbefDZP5ZTqAo6H_vfW0qXAC_8nZjUH5t29kg3fQxT3jgdX8W7LICH3HljwWrQ==; ttcid=0a96dddce36445e7985a26644bcd1c2838; tt_scid=x5HmLKn3YCuVO5Es4Lo.ii6jV8JTAmxoSEMDWMYcP86MqWrLbvCl4T26lnzG67EF2e02; _dd_s=logs=1&id=3d366a1e-1ec4-4e84-a293-6ed124836e03&created=1702435059345&expire=1702436139324",
# "Host": "m.douyin.com",
# "Referer": "https://www.douyin.com/",
# "Sec-Fetch-Dest": "document",
# "Sec-Fetch-Mode": "navigate",
# "Sec-Fetch-Site": "same-origin",
# "Sec-Fetch-User": "?1",
# "Upgrade-Insecure-Requests": "1",
# "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1"}

    header = {
        # "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
# "Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
# "Cache-Control":"max-age=0",
# "Connection": "keep-alive",
# "Cookie": "ttwid=1%7CbopXZucLd0bVc9JGao7U1gAuFK0qJ-mEwdRhLO1Ckas%7C1670663338%7C8205e2f2d51779f9768e9bd158a8563df0d38f37990de22513875ec0f64a0f30; n_mh=InES1BRVmb6X4Dotgvt2eX6_2xGe60HhkoNxrl0aqB0; LOGIN_STATUS=1; store-region=cn-bj; store-region-src=uid; my_rd=1; passport_csrf_token=1b4500e4563f57661e7e7761214a2bd0; passport_csrf_token_default=1b4500e4563f57661e7e7761214a2bd0; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.6%7D; SEARCH_RESULT_LIST_TYPE=%22single%22; IsDouyinActive=true; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A2880%2C%5C%22screen_height%5C%22%3A1620%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A4%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A250%7D%22; home_can_add_dy_2_desktop=%221%22; strategyABtestKey=%221702434974.731%22; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCSHBqWnRPdk5nS0phWmhIeEgzTUdJandSNmJkbVlheHkrMVAwczdBVG1jYVZCcC90Vnl4QWw2ZmFDc0pEWmhaYXhVZ0EwVlBjZnpFUWw4SW5EcGRYU2s9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; bd_ticket_guard_client_web_domain=2; pwa2=%220%7C0%7C1%7C0%22; s_v_web_id=verify_lq35voy0_77FJbCKc_ZVkb_4qae_AotC_znF0zK21CDdd; msToken=NMgqZtWW3cGLBeABUWmh9W6K3Wj7XFkx72VK0-J6PD91xIj-mn4sWWiyKbefDZP5ZTqAo6H_vfW0qXAC_8nZjUH5t29kg3fQxT3jgdX8W7LICH3HljwWrQ==; ttcid=0a96dddce36445e7985a26644bcd1c2838; tt_scid=x5HmLKn3YCuVO5Es4Lo.ii6jV8JTAmxoSEMDWMYcP86MqWrLbvCl4T26lnzG67EF2e02; _dd_s=logs=1&id=3d366a1e-1ec4-4e84-a293-6ed124836e03&created=1702435059345&expire=1702436139324",
"Host": "m.douyin.com",
"Referer": "https://www.douyin.com/",
# "Sec-Fetch-Dest": "document",
# "Sec-Fetch-Mode": "navigate",
# "Sec-Fetch-Site": "same-origin",
# "Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1"}
    url =  f"https://m.douyin.com/share/note/7278620731125140777" 
    res = session.get(url,headers=header)
    res.encoding = 'utf-8'
    # print(res.json())
    # print(res.text)
    print(res.content)
    # et = etree.HTML(res.text)
    # findList = et.xpath('//div[@class="col-xl-3 col-lg-3 col-md-3 col-sm-4 col-4 sticker-pack-cols"]')aweme-share-swiper-container aweme-share-swiper-container__horizontal
    # print(findList)
    # # title = et.xpath('//h1[@id="myheader"]/text()')[0]
    # for item in findList:
    #     img_url = item.xpath(".//img/@src")[0].rsplit('?',1)[0]
    #     print(img_url)
    #     image_respon = requests.get(img_url)
    #     filepath = f"一二布布/xpath/{img_url}"
    #     folderpath = os.path.dirname(filepath)
    #      # 如果文件夹不存在，创建文件夹
    #     if not os.path.exists(folderpath):
    #         os.makedirs(folderpath)

    #     # print(folderpath)    
    #     with open(filepath, 'wb') as f:#f'/Users/apple/gitee/think-for-yourself/Scrapy学习/tutorial/images/{imageName}'
    #         f.write(image_respon.content)
    # https://p3-sign.douyinpic.com/tos-cn-i-0813/oUADvtFgIgYAN5ACwFynbAa9sGAeAAtgAQelQQ~tplv-dy-lqen-new-water:1170:1558:5oqW6Z-z5Y-377yaNjQ2NjQ3NTA0OTk=:q80.webp?x-expires=1705024800&x-signature=zPp3YXgkQOsLQ12Se6yVlkHKDEQ%3D&sig=vUWrmcVKqIDsrPoFBqVdycmUPNU%3D&from=3213915784&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sc=image&biz_tag=aweme_images&l=20231213104057B43220D68203024C13B9
    pass

douyin();

    # <section id="stickerPack">
    #     <div class="container">
    #                     <div id="stickerInstallBlock">
    #             <a href="javascript:void(0);" data-href="https://getstickerpack.com/s/38737" role="button" id="installBtn" class="text-center btn d-inline btn-success">Install Stickers</a>
    #             <span>Downloads: 14920</span>

    #             <div class="clearfix"></div>
    #         </div>
    #                     <div class="row">
    #                             <div class="col-xl-3 col-lg-3 col-md-3 col-sm-4 col-4 sticker-pack-cols">
    #                                         <img src="https://s3.getstickerpack.com/storage/uploads/sticker-pack/xiong-mao-yi-erdi-ba-dan-bu-bu-1/sticker_1.gif?f995e10d61f128c4da55712e74a05b64" data-src-large="https://s3.getstickerpack.com/storage/uploads/sticker-pack/xiong-mao-yi-erdi-ba-dan-bu-bu-1/sticker_1.gif?f995e10d61f128c4da55712e74a05b64" class="img-thumbnail sticker-image" alt="sticker image #1" />
    #                                 </div>